
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';

class Constant{
  static getDir() async {
    appDirectory = await getApplicationDocumentsDirectory();
  }
  static late Directory appDirectory;

  static List audioList = [
    'assets/audios/audio1.mp3',
    'assets/audios/audio2.mp3',
    'assets/audios/audio3.mp3',
    'assets/audios/audio4.mp3',
  ];

  static saveAssetToAppDirectory() async{
    for (var element in audioList) {
      var fileName = path.basename(element);
      var file = File('${appDirectory.path}/$fileName');
      await file.writeAsBytes(
          (await rootBundle.load('assets/audios/$fileName'))
              .buffer
              .asUint8List());
    }

    print(Constant.appDirectory.path);
  }

  static String getAppDirectory(String assetsPath){
    var fileName = path.basename(assetsPath);
    return '${appDirectory.path}/$fileName';
  }
}